﻿
namespace Patterns4Net.Core.CecilExtensions
{
    using System.Diagnostics.Contracts;
    using Mono.Cecil;

    public class ConstructorCall
    {
        public ConstructorCall(MethodReference constructor, StackItem[] parameters)
        {
            Contract.Requires(constructor != null);
            Contract.Requires(parameters != null);
            Contract.Ensures(this.Parameters == parameters);
            Contract.Ensures(this.Constructor == constructor);
            this.Parameters = parameters;
            this.Constructor = constructor;
        }

        public TypeReference Type
        {
            get
            {
                Contract.Ensures(Contract.Result<TypeReference>() != null);
                return this.Constructor.DeclaringType;
            }
        }

        public StackItem[] Parameters { get; private set; }

        public MethodReference Constructor { get; private set; }        

        [ContractInvariantMethod]
        private void Invariant()
        {
            Contract.Invariant(this.Constructor != null);
            Contract.Invariant(this.Parameters != null);
        }
    }
}
